<?php

/*
 * Action
 * 
 * 3$
 * 
 * +1 Card; +1 Action
 * At the start of Clean-up this turn, you may choose an Action card you have in play. If you discard it from play this turn, put it on your deck.
 * 
 */

class Scheme extends Card implements iAction, iKingdom, iHinterlands {

    public function __construct() {
        parent::__construct("Scheme", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "At the start of Clean-up this turn, you may choose an Action card you have in play. If you discard it from play this turn, put it on your deck.");
    }

    public function cleanup(Game $game) {
        $playArea = $game->getPlayArea();
        $actions = array();
        foreach ($playArea as $card) {
            if ($card instanceof iAction) {
                $actions[] = $card;
            }
        }

        $actions = getUniqueCards($actions);
        $activeDuration = $game->getDurationAffects();
        foreach ($activeDuration as $card_arr) {
            $quantity = $card_arr['quantity'];
            if ($quantity > 0) {
                $name = $card_arr['card']->getValue();
                for ($i = 0; $i < sizeof($actions); $i+=1) {
                    $actionName = $actions[$i]->getValue();
                    if ($actionName == $name) {
                        array_splice ($actions, $i);
                        break;
                    }
                }
            }
        }
        if ($actions > 0) {
            $actions[] = new Option(1, 'None');
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $actions, 1, 1, null, "Choose card to put on top of your deck");
            $answer = $output[0];
            if ($answer != 'None') {
                $card = $game->moveCardFromPileToPile($answer, PlayArea, DrawPile);
                ScreenDisplay::addScreenMessage($game, true, "return ".  nicePrint($card)." on top of your deck  ", " returns ".ScreenDisplay::$LMSG. " on top of his deck");
            }
            else {
                #do nothing
            }
        }
        else {
            #do nothing
        }
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action and draw " . nicePrint($drawed_cards), "gets +1 action and draws " . sizeof($drawed_cards) . " cards");
    }

}